<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>postMessage iframe</title>
    <style>

    </style>
</head>

<body>
    <h1>iframe</h1>
    <button id="btnUser">获取用户信息</button>
</body>
<script src="./42.js"></script>
<script>
    PostMessage.connect(window.parent).then(() => {
        document.getElementById('btnUser').onclick = () => {
            PostMessage.postParent('getUserInfo', {}).then(res => {
                console.log(res)
            })
        }
        PostMessage.register('getMore', e => {
            return {
                name: 'abc',
                ...e
            }
        })
    })
    // let parentPath = ''
    // function getUserInfo() {
    //     window.parent.postMessage({
    //         type: 'getUserInfo'
    //     }, parentPath)
    // }
    // window.addEventListener("message", evt => {
    //     const { type, data } = evt.data
    //     if (type === 'getUserInfo') {
    //         console.log(data)
    //     } else if (type === 'sendUrl') {
    //         parentPath = data
    //     }
    // }, false)
</script>

</html>